package com.gxuwz.PangGuangyao.business.dao;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;

import com.gxuwz.PangGuangyao.business.entity.SysEquipmentAcc;
import com.gxuwz.core.dao.impl.BaseDaoImpl;
import com.gxuwz.core.pagination.Result;

/**
 * A data access object (DAO) providing persistence and search support for
 * SysLoginRecord entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * 
 * @see com.gxuwz.PangGuangyao.business.dao.SysLoginRecord
 * @author MyEclipse Persistence Tools
 */
@Repository("sysEquipmentAccDAO")
public class SysEquipmentAccDAO extends BaseDaoImpl<SysEquipmentAcc> {
	private static final Logger log = LoggerFactory
			.getLogger(SysEquipmentAccDAO.class);

	protected void initDao() {
		// do nothing
	}

//	public void save(SysLoginRecord transientInstance) {
//		log.debug("saving SysLoginRecord instance");
//		try {
//			getHibernateTemplate().save(transientInstance);
//			log.debug("save successful");
//		} catch (RuntimeException re) {
//			log.error("save failed", re);
//			throw re;
//		}
//	}

	public void delete(SysEquipmentAcc persistentInstance) {
		log.debug("deleting SysEquipmentAcc instance");
		try {
			if(persistentInstance != null){
				getHibernateTemplate().delete(persistentInstance);
				log.debug("delete successful");
			}
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public SysEquipmentAcc findById(java.lang.String EaId) {
		log.debug("getting SysEquipmentAcc instance with id: " + EaId);
		try {
			SysEquipmentAcc instance = (SysEquipmentAcc) getHibernateTemplate()
					.get("com.gxuwz.PangGuangyao.business.dao.SysEquipmentAcc",
							EaId);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<?> findAll() {
		log.debug("finding all SysEquipmentAcc instances");
		try {
			String queryString = "from SysEquipmentAcc";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public static SysEquipmentAccDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (SysEquipmentAccDAO) ctx.getBean("SysEquipmentAccDAO");
	}

	@SuppressWarnings("unchecked")
	public Result<SysEquipmentAcc> find(int page, int size, String logtype) {
		String queryString="from SysEquipmentAcc where 1=1";
		
		if("1".equals(logtype))
		{
			queryString = queryString + " and bstate = 1";
		}
		
		if("2".equals(logtype))
		{
			queryString = queryString + " and bstate = 2";
		}
		
		int start=(page-1)*size;
		int limit =size;
		return (Result<SysEquipmentAcc>)super.find(queryString, null, null, start, limit);
	}
}